package collection;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 对Point集合进行排序
 */
public class SortPoint {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(1, 2));
        list.add(new Point(40, 34));
        list.add(new Point(15, 20));
        list.add(new Point(28, 95));
        System.out.println("list原样输出" + list);
        Collections.sort(list, (o1, o2) -> {
                    int len1 = o1.getX() * o1.getX() + o1.getY() * o1.getY();
                    int len2 = o2.getX() * o2.getX() + o2.getY() * o2.getY();
                    return len1 - len2;
                }
        );
        System.out.println("list排序后输出" + list);

    }
}
